package com.thoughtworks.impersonator.http.verify;

import static com.thoughtworks.impersonator.http.IntegrationTestUtils.get;
import static com.thoughtworks.impersonator.http.IntegrationTestUtils.startServer;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.eclipse.jetty.server.Server;
import org.junit.Test;

import com.thoughtworks.impersonator.http.message.RequestIdentifier;
import com.thoughtworks.impersonator.http.record.Recorder;
import com.thoughtworks.impersonator.http.test.FixedUidRequestIdentifier;

public class VerifierTest {

    private static final int SERVER_PORT = 9910;
    private static final int RECORDER_PORT = SERVER_PORT + 1;

    @Test
    public void verifierTest() throws Exception {
        RequestIdentifier requestIdentifier = new FixedUidRequestIdentifier("w00t");
        File storageDir = new File("target/tmp/verifier");

        Server server = startServer(SERVER_PORT, "w00t");

        Recorder recorder = new Recorder(RECORDER_PORT, "127.0.0.1", SERVER_PORT, storageDir, requestIdentifier);
        get("http://127.0.0.1:" + RECORDER_PORT);
        recorder.stop();

        Verifier verifier = new Verifier("127.0.0.1", SERVER_PORT, storageDir, requestIdentifier);
        assertTrue(verifier.verify());

        server.stop();
    }

}
